﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static CLVisionLightControlTS.IOTriggerControl;

namespace CLVisionLightControlTS
{
    public abstract class AbstractIODevice
    {
        public static int nCurCardID = 0;
        // IO卡类型枚举
        public enum CardType
        {
            Card16,
            Card32
        }

        // 打开IO设备
        public abstract bool OpenIODevice(int CardID, out int ErrorCode, out string ErrorText, out bool Occurred);
        // 关闭IO设备
        public abstract bool CloseIODevice(int CardID, out int ErrorCode, out string ErrorText, out bool Occurred);
        // 按照光源配方号lightConfigNo触发DO
        public abstract bool TriggerLight(int CardID, int IOGroup, int lightConfigNo, out int ErrorCode, out string ErrorText, out bool Occurred);
        // 设置DO
        public abstract bool SetOutPutData(int CardID, long OutPutData, out int ErrorCode, out string ErrorText, out bool Occurred);
        // 获取DO
        public abstract bool GetOutPutData(int CardID, out long OutPutData, out int ErrorCode, out string ErrorText, out bool Occurred);
        // 获取DI
        public abstract bool GetInPutData(int CardID, out long InPutData, out int ErrorCode, out string ErrorText, out bool Occurred);
        // 设置DO Bit位
        public abstract bool WriteOutPutBit(int CardID, int PortBit, int Value, out int ErrorCode, out string ErrorText, out bool Occurred);
        // 获取DO Bit位
        public abstract bool ReadOutPutBit(int CardID, int PortBit, out int Value, out int ErrorCode, out string ErrorText, out bool Occurred);
        // 获取DI Bit位
        public abstract bool ReadInPutbit(int CardID, int PortBit, out int Value, out int ErrorCode, out string ErrorText, out bool Occurred);


        // Binary二进制按位取反
        public string ReverseBinaryString(string binary)
        {
            char[] charArray = binary.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }
        // Binary二进制倒序
        public string InvertBinaryString(string binary)
        {
            char[] invertedChars = new char[binary.Length];
            for (int i = 0; i < binary.Length; i++)
            {
                if (binary[i] == '0')
                {
                    invertedChars[i] = '1';
                }
                else if (binary[i] == '1')
                {
                    invertedChars[i] = '0';
                }
            }
            return new string(invertedChars);
        }
    }
}
